package com.eas.web.home.utils;

import org.apache.commons.lang.StringUtils;

import com.eas.biz.service.statistic.query.StatisticServiceQuery;

public class StatisticQueryUtil {

    public static void buildSortParameter(StatisticServiceQuery query, String sortField,
            String sortOrder) {
        if (StringUtils.isNotEmpty(sortField) && "avg_score".equals(sortField)) {
            if (StringUtils.isNotEmpty(sortOrder) && "desc".equals(sortOrder)) {
                query.sortByAvgScore(true);
            } else {
                query.sortByAvgScore(false);
            }
        } else if (StringUtils.isNotEmpty(sortField) && "max_score".equals(sortField)) {
            if (StringUtils.isNotEmpty(sortOrder) && "desc".equals(sortOrder)) {
                query.sortByMaxScore(true);
            } else {
                query.sortByMaxScore(false);
            }
        } else if (StringUtils.isNotEmpty(sortField) && "min_score".equals(sortField)) {
            if (StringUtils.isNotEmpty(sortOrder) && "desc".equals(sortOrder)) {
                query.sortByMinScore(true);
            } else {
                query.sortByMinScore(false);
            }
        } else {
            if (StringUtils.isNotEmpty(sortOrder) && "desc".equals(sortOrder)) {
                query.sortByDiviation(true);
            } else {
                query.sortByDiviation(false);
            }
        }
    }
}
